import java.util.Random;
import java.util.UUID;
import java.util.concurrent.*;

/**
 * @Author Stringzhua
 * @Date 2024/10/30 11:43
 * description:
 */
public class ThreadPool01 {
    public static void main(String[] args) {
        //通过有参构造方法创建线程池,自定义配置参数,创建线程池
        ThreadPoolExecutor threadPool1 = new ThreadPoolExecutor(10, 20, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5));
        //通过工具类创建线程池
        ExecutorService threadPool2 = Executors.newFixedThreadPool(10);


        //提交线程任务,submit()底层是execute()
        for (int i = 0; i < 1000; i++) {
            threadPool1.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "-->" + UUID.randomUUID());
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        threadPool1.shutdown();
    }
}
